#!/bin/bash
# This is a ShellScript For Auto Install LNMP and Moodle on CentOS
# Add executive privilege
# chmod 755 centos.sh
# Powered by hongm
# Visted http://hongm.emoodle.org
# Modify 2016-05-10
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

##Download Server##
Download_Mirror="http://hongm.emoodle.org:8080/down"
##Moodle WebSite Home Directory##
Default_Moodle_Dir="/www"
##Moodle Code##
MoodleFileName="moodle_git.tgz"
##MariaDB database directory##
MariaDB_Data_Dir="${Default_Moodle_Dir}/mariadb"


#ConfigFiles
NginxConfigFile="/etc/nginx/nginx.conf"
NginxDefaultFile="/etc/nginx/conf.d/default.conf"
MariaDBConfigFile="/etc/my.cnf.d/server.cnf"
PHPConfigFile="/etc/php.ini"
FPMConfigFile="/etc/php-fpm.d/www.conf"

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script"
    exit 1
fi

clear
echo ""
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
    if grep -Eqi "release 6." /etc/redhat-release; then
        CentOS_Ver='6'
        CentOS_Version=$(cat /etc/redhat-release | awk -F " " '{print $3}')
        #Check IP Configure File
        Network_Config=$( ls /etc/sysconfig/network-scripts/ | grep ifcfg-e )
        echo -e " \e[0;33mYour Current CentOS Version: \e[0;31m${CentOS_Version}\e[0m"
        IP=$(ip addr | grep inet | grep brd | awk '{ print $2; }' | sed 's/\/.*$//')
     else
        echo -e " \e[0;31mYour OS is not CentOS 6 !\e[0m"
        exit 1
    fi
 else
    echo -e " \e[0;31mYour OS is not CentOS!\e[0m"
    exit 1
fi

#set MariaDB root password
echo "======================================================="
DB_Root_PWD="123456"
echo -e " \e[0;33mPlease setup root password of MariaDB.(Default password: 123456)\e[0m"
read -p "Please enter: " DB_Root_PWD
if [ "${DB_Root_PWD}" = "" ]; then
     DB_Root_PWD="123456"
fi
echo -e " \e[0;32mMySQL root password: \e[0;31m${DB_Root_PWD}\e[0m"

#set Moodle admin email
echo "======================================================="
MoodleAdminEmail="admin@163.com"
echo -e " \e[0;33mPlease setup E-mail of Moodle Admin.(Default email: admin@163.com)\e[0m"
read -p "Please enter: " MoodleAdminEmail
if [ "${MoodleAdminEmail}" = "" ]; then
     MoodleAdminEmail="admin@163.com"
fi
echo -e " \e[0;32mMoodle admin E-mail: \e[0;31m${MoodleAdminEmail}\e[0m"


echo ""
echo "Press any key to install...or Press Ctrl+c to cancel"
OLDCONFIG=`stty -g`
stty -icanon -echo min 1 time 0
dd count=1 2>/dev/null
stty ${OLDCONFIG}


if [ "${Download_Mirror}" = "http://hongm.emoodle.org:8080/down" ]; then
    mirror_code=`curl -o /dev/null -m 20 --connect-timeout 20 -sk -w %{http_code} http://hongm.emoodle.org:8080/down/`
    if [ "${mirror_code}" != "200" ]; then
        mirror_code=`curl -o /dev/null -m 20 --connect-timeout 20 -sk -w %{http_code} http://study.wjszzx.com.cn/soft/`
        if [ "${mirror_code}" = "200" ]; then
            echo "Change to mirror http://study.wjszzx.com.cn/soft"
            Download_Mirror='http://study.wjszzx.com.cn/soft'
         else
            echo "Dwonload Server Error!"
            exit 1
        fi
    fi
fi

if cat /etc/sysconfig/iptables | grep "INPUT -p tcp --dport 80 -j ACCEPT"; then 
    echo "Firewall configuration for HTTP "
 else
    sed -i '/-A INPUT -i lo -j ACCEPT/a\-A INPUT -p tcp --dport 80 -j ACCEPT\n-A INPUT -p tcp --dport 443 -j ACCEPT\n-A INPUT -p tcp --dport 3306 -j ACCEPT' /etc/sysconfig/iptables
fi
service iptables restart
if cat /etc/selinux/config | grep "^SELINUX=enforcing" ; then
    sed -i 's:SELINUX=enforcing:#SELINUX=enforcing\nSELINUX=disabled:g' /etc/selinux/config
    setenforce 0
fi

# Modify repo
sed -i 's:mirrorlist=:#mirrorlist=:g' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's:#baseurl=:baseurl=:g' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's:mirror.centos.org:mirrors.ustc.edu.cn:g' /etc/yum.repos.d/CentOS-Base.repo

echo '[epel]' > /etc/yum.repos.d/epel.repo
echo 'name=Extra Packages for Enterprise Linux 6 - $basearch' >> /etc/yum.repos.d/epel.repo
echo 'baseurl=http://mirrors.ustc.edu.cn/epel/6/$basearch' >> /etc/yum.repos.d/epel.repo
echo '#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch' >> /etc/yum.repos.d/epel.repo
echo 'failovermethod=priority' >> /etc/yum.repos.d/epel.repo
echo 'enabled=1' >> /etc/yum.repos.d/epel.repo
echo 'gpgcheck=1' >> /etc/yum.repos.d/epel.repo
echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6' >> /etc/yum.repos.d/epel.repo

echo '[remi]' > /etc/yum.repos.d/remi.repo
echo 'name=Remi RPM repository for Enterprise Linux 6 - $basearch' >> /etc/yum.repos.d/remi.repo
echo 'baseurl=http://mirrors.ustc.edu.cn/remi/enterprise/6/remi/$basearch/' >> /etc/yum.repos.d/remi.repo
echo '#mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror' >> /etc/yum.repos.d/remi.repo
echo 'enabled=1' >> /etc/yum.repos.d/remi.repo
echo 'gpgcheck=1' >> /etc/yum.repos.d/remi.repo
echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi' >> /etc/yum.repos.d/remi.repo
echo '[remi-safe]' >> /etc/yum.repos.d/remi.repo
echo 'name=Safe Remi RPM repository for Enterprise Linux 6 - $basearch' >> /etc/yum.repos.d/remi.repo
echo 'baseurl=http://mirrors.ustc.edu.cn/remi/enterprise/6/safe/$basearch/' >> /etc/yum.repos.d/remi.repo
echo '#mirrorlist=http://rpms.remirepo.net/enterprise/6/safe/mirror' >> /etc/yum.repos.d/remi.repo
echo 'enabled=1' >> /etc/yum.repos.d/remi.repo
echo 'gpgcheck=1' >> /etc/yum.repos.d/remi.repo
echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi' >> /etc/yum.repos.d/remi.repo
echo '[remi-php71]' >> /etc/yum.repos.d/remi.repo
echo 'name=Remi PHP 7.1 RPM repository for Enterprise Linux 6 - $basearch' >> /etc/yum.repos.d/remi.repo
echo 'baseurl=http://mirrors.ustc.edu.cn/remi/enterprise/6/php71/$basearch/' >> /etc/yum.repos.d/remi.repo
echo '#mirrorlist=http://rpms.remirepo.net/enterprise/6/php71/mirror' >> /etc/yum.repos.d/remi.repo
echo 'enabled=1' >> /etc/yum.repos.d/remi.repo
echo 'gpgcheck=1' >> /etc/yum.repos.d/remi.repo
echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi' >> /etc/yum.repos.d/remi.repo

echo "[nginx]" > /etc/yum.repos.d/nginx.repo
echo "name=nginx repo" >> /etc/yum.repos.d/nginx.repo
echo 'baseurl=http://nginx.org/packages/centos/6/$basearch/' >> /etc/yum.repos.d/nginx.repo
echo "gpgcheck=0" >> /etc/yum.repos.d/nginx.repo
echo "enabled=1" >> /etc/yum.repos.d/nginx.repo

echo "[mariadb]" > /etc/yum.repos.d/MariaDB.repo
echo "name=MariaDB" >> /etc/yum.repos.d/MariaDB.repo
echo "baseurl=http://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos6-amd64" >> /etc/yum.repos.d/MariaDB.repo
echo "gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB" >> /etc/yum.repos.d/MariaDB.repo
echo "gpgcheck=1" >> /etc/yum.repos.d/MariaDB.repo
echo "enabled=1" >> /etc/yum.repos.d/MariaDB.repo

rm -fr /var/cache/yum/x86_64
yum -y makecache
yum -y update
yum -y install git wget nano

if [ ! -f /etc/pki/rpm-gpg/RPM-GPG-KEY-remi ]; then
    if [ -f conf/RPM-GPG-KEY-remi ]; then
        cp conf/RPM-GPG-KEY-remi /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
     else
        wget https://rpms.remirepo.net/RPM-GPG-KEY-remi -O /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
    fi
fi
if [ ! -f /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 ]; then

    if [ -f conf/RPM-GPG-KEY-EPEL-6 ]; then
        cp conf/RPM-GPG-KEY-EPEL-6 /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
     else
        wget http://mirrors.ustc.edu.cn/epel/RPM-GPG-KEY-EPEL-6 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    fi
fi

echo -e " \e[0;31m[+] Yum installing Nginx+MariaDB+PHP ...\e[0m"
n=0
flag=1
while [ $n -le 8 -a $flag -gt 0 ]
do
    yum -y install MariaDB-server nginx php php-fpm php-mysqlnd php-mbstring php-mcrypt php-gd php-xml php-xmlrpc php-curl php-xsl php-intl php-opcache php-soap php-zip php-tidy php-pear
    flag=$?
    n=$((n+1))
done
if [ $n -ge 8 ]; then
    echo -e "\e[0;31m[+] Yum Error!\e[0m"
    exit 1
fi

echo -e " \e[0;32m[+] Modify MariaDB config ...\e[0m"
service mysql restart
/usr/bin/mysqladmin -u root password ${DB_Root_PWD}
cat > /tmp/mariadb_sec_script<<EOF
update mysql.user set password=password('${DB_Root_PWD}') where user='root';
delete from mysql.user where not (user='root');
delete from mysql.user where user='root' and password='';
grant all on moodle.* to 'moodle'@'localhost' identified by '${DB_Root_PWD}';
grant all on moodle.* to 'moodle'@'127.0.0.1' identified by '${DB_Root_PWD}';
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
flush privileges;
EOF
/usr/bin/mysql -u root -p${DB_Root_PWD} -h localhost < /tmp/mariadb_sec_script
rm -f /tmp/mariadb_sec_script
service mysql stop
mkdir -p ${MariaDB_Data_Dir}/logs
cp -a /var/lib/mysql ${MariaDB_Data_Dir}/data
chown -R mysql:mysql ${MariaDB_Data_Dir}/data
chown -R mysql:mysql ${MariaDB_Data_Dir}/logs
cat > ${MariaDBConfigFile}<<EOF
[client]
port	= 3306
socket	= /tmp/mysql.sock
[mysqld]
port	= 3306
socket	= /tmp/mysql.sock
user    = mysql
basedir = /usr
datadir = ${MariaDB_Data_Dir}/data
log_error = ${MariaDB_Data_Dir}/logs/mariadb.err
pid-file = ${MariaDB_Data_Dir}/data/mariadb.pid
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
tmp_table_size = 16M
table_open_cache = 64
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=${MariaDB_Data_Dir}/logs/mysql-bin
binlog_format=mixed
server-id	= 1
expire_logs_days = 10
default_storage_engine = InnoDB
innodb_data_home_dir = ${MariaDB_Data_Dir}/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = ${MariaDB_Data_Dir}/data
innodb_buffer_pool_size = 128M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_file_format	= Barracuda
innodb_file_format_check= 1
innodb_file_format_max 	= Barracuda
innodb_file_per_table	= 1
EOF
service mysql restart
chkconfig --add mysql
chkconfig mysql on

echo -e " \e[0;32m[+] Modify PHP config ...\e[0m"
sed -i 's/post_max_size = 8M/post_max_size = 2048M/g' ${PHPConfigFile}
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 2048M/g' ${PHPConfigFile}
sed -i 's/;date.timezone =/date.timezone = PRC/g' ${PHPConfigFile}
sed -i 's/short_open_tag = Off/short_open_tag = On/g' ${PHPConfigFile}
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' ${PHPConfigFile}
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' ${PHPConfigFile}
sed -i 's/max_input_time = 60/max_input_time = 600/g' ${PHPConfigFile}
sed -i 's/default_socket_timeout = 60/default_socket_timeout = 600/g' ${PHPConfigFile}
sed -i 's/memory_limit = 128M/memory_limit = 4096M/g' ${PHPConfigFile}
sed -i 's/user = apache/user = nginx/g' ${FPMConfigFile}
sed -i 's/group = apache/group = nginx/g' ${FPMConfigFile}
service php-fpm restart
chkconfig --add php-fpm
chkconfig php-fpm on

echo -e " \e[0;32m[+] Modify Nginx config ...\e[0m"
sed -i 's/worker_processes  1;/worker_processes  auto;\nworker_rlimit_nofile  65535;/g' ${NginxConfigFile}
sed -i 's/worker_connections  1024;/worker_connections  10240;\n    use epoll;/g' ${NginxConfigFile}
sed -i 's/#tcp_nopush     on;/tcp_nopush     on;\n    client_max_body_size 2048m;\n    client_header_buffer_size 32k;\n    large_client_header_buffers 4 32k;\n    server_names_hash_bucket_size 128;\n    fastcgi_connect_timeout 300;\n    fastcgi_send_timeout 300;/g' ${NginxConfigFile}
sed -i '/fastcgi_send_timeout 300;/a\    fastcgi_read_timeout 300;\n    fastcgi_buffer_size 64k;\n    fastcgi_buffers 4 64k;\n    fastcgi_busy_buffers_size 128k;\n    fastcgi_temp_file_write_size 256k;' ${NginxConfigFile}
echo "server {" > ${NginxDefaultFile}
echo "    listen       80;" >> ${NginxDefaultFile}
echo "    server_name  localhost;" >> ${NginxDefaultFile}
echo "    root   ${Default_Moodle_Dir}/moodle;" >> ${NginxDefaultFile}
echo "    index  index.php index.html index.htm;" >> ${NginxDefaultFile}
echo "    location ~ \.php$ {" >> ${NginxDefaultFile}
echo "        fastcgi_pass   127.0.0.1:9000;" >> ${NginxDefaultFile}
echo "        fastcgi_index  index.php;" >> ${NginxDefaultFile}
echo '        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;' >> ${NginxDefaultFile}
echo "        include        fastcgi_params;" >> ${NginxDefaultFile}
echo "    }" >> ${NginxDefaultFile}
echo '    if (!-e $request_filename) {' >> ${NginxDefaultFile}
echo '        rewrite "^(.*\.php)(/)(.*)$" $1?file=/$3 last;' >> ${NginxDefaultFile}
echo "    }" >> ${NginxDefaultFile}
echo "}" >> ${NginxDefaultFile}
service nginx restart
chkconfig --add nginx
chkconfig nginx on

echo -e " \e[0;32m[+] Download Moodle Git Clone ...\e[0m"
if [ -s "${MoodleFileName}" ]; then
    echo "${MoodleFileName} [found]"
 else
    echo "Error: ${MoodleFileName} not found!!!download now..."
    wget -c ${Download_Mirror}/moodle/moodle_git.tgz
fi

echo -e " \e[0;32m[+] Install Moodle Soucre...\e[0m"
mkdir -p ${Default_Moodle_Dir}
tar zxf ${MoodleFileName} -C ${Default_Moodle_Dir}/
rm -f ${MoodleFileName}
cd ${Default_Moodle_Dir}/moodle
git reset --hard
git pull
Stable_Version=$( git branch -a | sed '$d' | sed -n '$p' | awk -F "_" '{print $2}' )
git branch --track MOODLE_${Stable_Version}_STABLE origin/MOODLE_${Stable_Version}_STABLE
git checkout MOODLE_${Stable_Version}_STABLE
git pull --force
echo '<?PHP  // Moodle configuration file' > ${Default_Moodle_Dir}/moodle/config.php
echo 'unset($CFG);' >> ${Default_Moodle_Dir}/moodle/config.php
echo 'global $CFG;' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG = new stdClass();' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->dbtype    = "mariadb";' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->dblibrary = "native";' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->dbhost    = "127.0.0.1";' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->dbname    = "moodle";' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->dbuser    = "moodle";' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->dbpass    = "'${DB_Root_PWD}'";' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->prefix    = "mdl_";' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->dboptions = array(' >> ${Default_Moodle_Dir}/moodle/config.php
echo '  "dbpersist" => 0,' >> ${Default_Moodle_Dir}/moodle/config.php
echo '  "dbport" => "",' >> ${Default_Moodle_Dir}/moodle/config.php
echo '  "dbsocket" => "",' >> ${Default_Moodle_Dir}/moodle/config.php
echo ');' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->wwwroot   = "http://'${IP}'";' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->dataroot  = "'${Default_Moodle_Dir}'/moodledata";' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->directorypermissions = 0777;' >> ${Default_Moodle_Dir}/moodle/config.php
echo '$CFG->admin = "admin";' >> ${Default_Moodle_Dir}/moodle/config.php
echo 'require_once(dirname(__FILE__) . "/lib/setup.php"); // Do not edit' >> ${Default_Moodle_Dir}/moodle/config.php
mkdir -p ${Default_Moodle_Dir}/moodledata
chown -R nginx:nginx ${Default_Moodle_Dir}/moodle
chown -R nginx:nginx ${Default_Moodle_Dir}/moodledata
chmod -R 755 ${Default_Moodle_Dir}/moodle
chmod -R 755 ${Default_Moodle_Dir}/moodledata
find ${Default_Moodle_Dir}/moodle -type f -exec chmod 0644 {} \;

n=0
while [ $n -le 8 -a ! -f ${MariaDB_Data_Dir}/data/moodle/mdl_user.frm ]
do
    sudo -u nginx /usr/bin/php ${Default_Moodle_Dir}/moodle/admin/cli/install_database.php --lang=zh_cn --adminpass=${DB_Root_PWD} --adminemail=${MoodleAdminEmail} --fullname=ITCenter --shortname=ITCenter --agree-license
    n=$((n+1))
done
if [ $n -ge 8 ]; then
    echo "Network error! Please continue to install http://${IP} in the browser!"
 else
    /usr/bin/mysql -u root -p${DB_Root_PWD} -h localhost -e "UPDATE moodle.mdl_config SET value='firstname,lastname' WHERE name='alternativefullnameformat';"
    /usr/bin/mysql -u root -p${DB_Root_PWD} -h localhost -e "UPDATE moodle.mdl_config SET value='0' WHERE name='defaulthomepage';"
    /usr/bin/mysql -u root -p${DB_Root_PWD} -h localhost -e "UPDATE moodle.mdl_config SET value='CN' WHERE name='country';"
    /usr/bin/mysql -u root -p${DB_Root_PWD} -h localhost -e "UPDATE moodle.mdl_config SET value='Asia/Shanghai' WHERE name='timezone';"
    /usr/bin/mysql -u root -p${DB_Root_PWD} -h localhost -e "UPDATE moodle.mdl_config SET value='' WHERE name='docroot';"
    /usr/bin/php ${Default_Moodle_Dir}/moodle/admin/cli/mysql_compressed_rows.php -f
fi


#Check_Files
isNginx=""
echo "============================== Check install =============================="
echo "Checking ..."
if [[ -s ${NginxConfigFile} && -s /usr/sbin/nginx ]]; then
    echo -e " \e[0;32mNginx: OK\e[0m"
    isNginx="ok"
 else
    echo -e " \e[0;31mError: Nginx install failed.\e[0m"
fi
isDB=""
if [[ -s /usr/bin/mysql && -s /usr/bin/mysqld_safe && -s ${MariaDBConfigFile} ]]; then
    echo -e " \e[0;32mMariaDB: OK\e[0m"
    isDB="ok"
 else
    echo -e " \e[0;31mError: MariaDB install failed.\e[0m"
fi
isPHP=""
if [[ -s /usr/sbin/php-fpm && -s ${PHPConfigFile} && -s /usr/bin/php ]]; then
    echo -e " \e[0;32mPHP: OK\e[0m"
    isPHP="ok"
 else
    echo -e " \e[0;31mError: PHP install failed.\e[0m"
fi
if [[ "$isNginx" = "ok" && "$isDB" = "ok" && "$isPHP" = "ok" ]]; then
    echo "------------------------------------------------------------------------"
    echo "      moodle ${Moodle_Version} for CentOS ${CentOS_Ver} Linux Server, Written by Hongm"
    echo "                 http://hongm.emoodle.org                               "
    echo "------------------------------------------------------------------------"
    if [ ${CentOS_Ver} -ge 7 ]; then
        echo "  Nginx:   systemctl {start|stop|reload|restart|status} nginx.service   "
        echo "  MariaDB: systemctl {start|stop|reload|restart|status} mysql.service "
        echo "  PHP-FPM: systemctl {start|stop|reload|restart|status} php-fpm.service "
    else
        echo "  Nginx:   service nginx {start|stop|reload|restart|status}             "
        echo "  MariaDB: service mysql {start|stop|reload|restart|status}           "
        echo "  PHP-FPM: service php-fpm {start|stop|reload|restart|status}           "
    fi
    echo "------------------------------------------------------------------------"
    echo "  Moodle Web Site: http://${IP}                                            "
    echo "  Moodle Soucre directory: ${Default_Moodle_Dir}/moodle                 "
    echo "  Moodle Data directory: ${Default_Moodle_Dir}/moodledata               "
    echo "------------------------------------------------------------------------"
    echo "  Moodle admin password: ${DB_Root_PWD}                                 "
    echo "------------------------------------------------------------------------"
    echo "  MariaDB root password: ${DB_Root_PWD}                                 "
    echo "------------------------------------------------------------------------"
 else
    echo -e " \e[0;31mSorry,Failed to install LNMP!\e[0m"
    echo -e " \e[0;31mYou can download moodle-install.log from your server,and mail install.log to hongm@sina.com.\e[0m"
fi

